﻿using UnityEditor;
using UnityEngine;

namespace EditorExtension
{
    public class GUI_API
    {
        private Rect mLabelRect = new Rect(20, 60, 200, 20);
        private Rect mTextFieldRect = new Rect(20, 90, 200, 20);
        private Rect mTextAreaRect = new Rect(20, 120, 200, 100);
        private Rect mPasswordFieldRect = new Rect(20, 240, 200, 20);
        private Rect mButtonRect = new Rect(20, 270, 200, 20);
        private Rect mRepeatButtonRect = new Rect(20, 300, 200, 20);
        private Rect mToggleRect = new Rect(20, 330, 200, 20);
        private Rect mToolbarRect = new Rect(20, 360, 400, 20);
        private Rect mBoxRect = new Rect(20, 390, 100, 100);
        private Rect mScrollViewRect = new Rect(20, 0, 400, 500);
        private Rect mHorizontalSliderRect = new Rect(20, 510, 100, 20);
        private Rect mVerticalSliderRect = new Rect(20, 540, 20, 100);
        private Rect mGroupRect = new Rect(20, 650, 100, 20);
        private Rect mWindowRect = new Rect(20, 680, 100, 100);
        
        private string mTextFieldValue = "TextField: Hello GUI API";
        private string mTextAreaValue = "TextArea:\n Hello GUI API";
        private string mPasswordFieldValue = "TextArea:\n Hello GUI API";
        private bool mToggleValue = false;
        private int mToolbarIndex = 0;
        private Vector2 mScrollPos = Vector2.zero;
        private float mSliderValue = 0.5f;
        public void Draw()
        {
            // 滚动视图
            mScrollPos = GUI.BeginScrollView(mScrollViewRect, mScrollPos, new Rect(0, 0, 400, 500));
            
            GUI.Label(mLabelRect, "Label: Hello GUI API"); // 文本

            mTextFieldValue = GUI.TextField(mTextFieldRect, mTextFieldValue); // 文本输入框

            mTextAreaValue = GUI.TextArea(mTextAreaRect, mTextAreaValue); // 文本输入区域

            mPasswordFieldValue = GUI.PasswordField(mPasswordFieldRect, mPasswordFieldValue, '$'); // 密码输入框
            
            // 按钮
            if (GUI.Button(mButtonRect, "Button"))
            {
                Debug.Log("GUI Button Clicked");
            }
            
            // 重复按钮
            if (GUI.RepeatButton(mRepeatButtonRect, "RepeatButton"))
            {
                Debug.Log("GUI RepeatButton Clicked");
            }
            
            mToggleValue = GUI.Toggle(mToggleRect, mToggleValue, "Toggle"); // 开关

            mToolbarIndex = GUI.Toolbar(mToolbarRect, mToolbarIndex, new[] { "Toolbar1", "Toolbar2", "Toolbar3" }); // 工具栏
            
            GUI.Box(mBoxRect, "这是GUI Box样式！"); // Box样式
            GUI.EndScrollView();

            mSliderValue = GUI.HorizontalSlider(mHorizontalSliderRect, mSliderValue, 0f, 1f); // 水平滑块
            
            mSliderValue = GUI.VerticalSlider(mVerticalSliderRect, mSliderValue, 0f, 1f); // 垂直滑块
            
            GUI.BeginGroup(mGroupRect, "Group");
            GUI.EndGroup();
            
            // 运行时显示
            GUI.Window(1000, mWindowRect, (id) => { }, "Window");
        }
    }
}